package Test;

import java.io.IOException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
 * 
 * @ClassName: TestOpenBrowser
 * @Description: 点击按钮打开默认浏览器
 * @author lizh
 * @date 2015年11月6日 上午10:20:43
 * @version v1.0
 */
public class TestOpenBrowser extends Thread {
  public static void main(String[] args) throws Exception {
   new TestOpenBrowser().start();
  }
  
  public void run(){
   goIntnet();
  }
  
  public void goIntnet(){
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setText("打开浏览器");
   shell.setBounds(300, 100, 600, 400);
   Button goIntenet = new Button(shell, SWT.NONE);
   goIntenet.setText("打开浏览器");
   goIntenet.setBounds(150, 80, 300, 200);
   goIntenet.addSelectionListener(new SelectionAdapter() {
   @Override
   public void widgetSelected(SelectionEvent e){
    try {
     Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler http://localhost:8080/");
    } catch (IOException e1) {
     e1.printStackTrace();
    }
   }
    
  });
      
      shell.open();
      while(!shell.isDisposed()){
       if(!display.readAndDispatch()){
        display.sleep();
       }
      }
     }
}
